package com.estronger.shopmanage.ui.order.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.ui.order.bean.BitmapItem;
import com.estronger.shopmanage.ui.order.bean.OrderBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-08-09.
 */

public class QueryAdapter extends BaseAdapter {
    private Activity mContext;
    protected LayoutInflater inflater;
    private List<OrderBean> myList;

    public QueryAdapter(Activity mContext) {
        this.mContext = mContext;
        this.inflater =LayoutInflater.from(mContext);
        this.myList = new ArrayList<OrderBean>();
    }

    @Override
    public int getCount() {
        return myList.size();
    }

    @Override
    public OrderBean getItem(int position) {
        return myList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void appendData(List<OrderBean> data, boolean isClearOld){
        if(data==null){
            return;
        }else if(isClearOld){
            myList.clear();
        }
        myList.addAll(data);
        notifyDataSetChanged();
    }
    public void resfNullData(){
        myList.clear();
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OrderBean order = myList.get(position);
        ViewHolder vh = null;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.layout_query_listitem, parent,false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        String title = "";
        if(order.getfHouses().equals("")){
            title = order.getfHouses();
        }else{
            title = order.getfHouses()+"-"+order.getfCusName();
        }
        vh.tvfItemTitle.setText(title);
        vh.tvfPhoneNo.setText(order.getfPhoneNumber());
        vh.tvfOrderDate.setText(order.getfOrdersTime());
        return convertView;
    }
    class ViewHolder{
        TextView tvfItemTitle;
        TextView tvfPhoneNo;
        TextView tvfOrderDate;

        public ViewHolder(View v) {
            this.tvfItemTitle = (TextView) v.findViewById(R.id.tvfOrderTitle);
            this.tvfPhoneNo = (TextView) v.findViewById(R.id.tvfPhoneno);
            this.tvfOrderDate = (TextView) v.findViewById(R.id.tvfOrderTime);
        }
    }
}
